<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/head :: htmlhead">

<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="oldpasswd" lay-verify="required" lay-verType="tips" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="newpasswd" id="newpasswd" lay-verify="required" lay-verType="tips"
                                       autocomplete="off" class="layui-input">
                            </div>
<!--                            <div class="layui-form-mid layui-word-aux">6到16个字符</div>-->
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="setmypass" style="padding-left: 12px">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // layui.config({
    //     base: '/static/lib/' //静态资源所在路径
    // }).extend({
    //     index: 'index' //主入口模块
    // }).use(['index']);

    layui.use(['form' ,'layer'], function() {
        var form = layui.form;
        var layer = layui.layer;
        form.verify({
            repass: function(value) {
                //获取密码
                var newpasswd = $("#newpasswd").val();
                if(value !== newpasswd){
                    return '两次密码不一致';
                }
            }
        });

        form.on("submit(setmypass)",function (data) {
            $.ajax({
                url:"/modifypwd",
                async: false,
                type:"POST",
                dataType: "text",
                data:data.field,
                success: function(data){
                    if(data==="oldPasswdError"){
                        layer.msg('原始密码错误！', {icon: 2});
                    }else if(data==="success"){
                        layer.msg('修改密码成功！', {icon: 1});

                        if (window != top){top.location.href = "/logout";}

                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>